#include "httpshowpic.h"
#include "ui_httpshowpic.h"

HttpShowPic::HttpShowPic(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::HttpShowPic)
{
    ui->setupUi(this);

    //当请求完毕manager会发送finished信号
    connect(&manager,&QNetworkAccessManager::finished,this,&HttpShowPic::read_data);

}

HttpShowPic::~HttpShowPic()
{
    delete ui;
}

void HttpShowPic::on_requreBt_clicked()
{
    //发送请求
    QUrl url(ui->lineEdit->text());
    QNetworkRequest request(url);
    manager.get(request);  //发送请求
}

void HttpShowPic::read_data(QNetworkReply* reply)
{
    //通过应答对象读取数据
    QByteArray array = reply->readAll();
    QPixmap mmp;
    mmp.loadFromData(array);   //把接收的数据存储在图片空间中
    mmp.save("./my.jpg");

    //设置尺寸
    mmp = mmp.scaled(ui->label->size());

    ui->label->setPixmap(mmp);



}
